package com.madi.company.ui.main.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aspsine.irecyclerview.baseadapter.BaseReclyerViewAdapter;
import com.jaydenxiao.common.commonutils.TimeUtil;
import com.madi.company.R;
import com.madi.company.bean.SearchResumeEntity;
import com.madi.company.ui.main.activity.ResumeDetailActivity;
import com.madi.company.utils.DnUtil;


/**
 * 简历列表adapter
 * Created by 丁宁
 * on 2017/2/14.
 */

public class SearchResumeAdapter extends BaseReclyerViewAdapter<SearchResumeEntity.RowsBean> {

    public SearchResumeAdapter(Context context) {
        super(context);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_search_resume, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        SearchResumeEntity.RowsBean rowsBean = data.get(position);
        final MyViewHolder myHolder = (MyViewHolder) holder;
        myHolder.mResumeTime.setText(TimeUtil.getMonthDate(rowsBean.getRefreshTime()));
        myHolder.mResumeHeadImage.setBackgroundResource(R.mipmap.resume_man);
        myHolder.mResumeuantity.setText(rowsBean.getMatchingCount() + "");
        myHolder.mResumeTitle.setText(rowsBean.getResumeName());
//        myHolder.mResumeSalary.setText(rowsBean.getSalaryBegin());
        if (0 == rowsBean.getSalaryBegin() && 0 == rowsBean.getSalaryEnd()) {
            myHolder.mResumeSalary.setText("");
        } else {
            myHolder.mResumeSalary.setText("￥" + rowsBean.getSalaryBegin() + "-" + rowsBean.getSalaryEnd() + "/" + mContext.getResources().getString(R.string.month));
        }
        // 错误写法先对付
        if (rowsBean.getCityName() == null || "".equals(rowsBean.getCityName())) {
            myHolder.mResumeAddress.setText("中国");
        } else {
            myHolder.mResumeAddress.setText(rowsBean.getCityName());
        }
        if (null == rowsBean.getExpTime() + "") {
            myHolder.searchResume_year.setText(mContext.getResources()
                    .getString(R.string.unknown));
        } else {
            if (rowsBean.getExpTime() > 1) {
                myHolder.searchResume_year.setText(rowsBean.getExpTime()
                        + mContext.getResources().getString(R.string.year_number));
            } else {
                myHolder.searchResume_year.setText(rowsBean.getExpTime()
                        + mContext.getResources().getString(R.string.year_odd_number));
            }

        }
        if (null == rowsBean.getEducation()) {
            myHolder.searchResume_education.setVisibility(View.GONE);
        } else {
            myHolder.searchResume_education.setVisibility(View.VISIBLE);
            switch (rowsBean.getEducation()) {
                case "0":
                    myHolder.searchResume_education.setText(mContext
                            .getResources().getString(R.string.dict_edu0));
                    break;
                case "1":
                    myHolder.searchResume_education.setText(mContext
                            .getResources().getString(
                                    R.string.dict_edu1));
                    break;
                case "2":
                    myHolder.searchResume_education.setText(mContext
                            .getResources()
                            .getString(R.string.dict_edu2));
                    break;
                case "3":
                    myHolder.searchResume_education.setText(mContext
                            .getResources().getString(R.string.dict_edu3));
                    break;
                case "4":
                    myHolder.searchResume_education.setText(mContext
                            .getResources().getString(R.string.dict_edu4));
                    break;
                case "5":
                    myHolder.searchResume_education.setText(mContext
                            .getResources().getString(R.string.dict_edu5));
                    break;
                case "6":
                    myHolder.searchResume_education.setText(mContext
                            .getResources().getString(
                                    R.string.dict_edu6));
                    break;
                case "7":
                    myHolder.searchResume_education.setText(mContext
                            .getResources().getString(R.string.dict_edu7));
                    break;
                case "8":
                    myHolder.searchResume_education.setText(mContext
                            .getResources().getString(R.string.dict_edu8));
                    break;
                case "9":
                    myHolder.searchResume_education.setText(mContext
                            .getResources().getString(R.string.dict_edu9));
                    break;
                default:
                    break;
            }
        }
        if (rowsBean.getLang() == null || "".equals(rowsBean.getLang())) {
            myHolder.searchResume_job.setVisibility(View.GONE);
        } else {
            myHolder.searchResume_job.setVisibility(View.VISIBLE);
            String language = DnUtil.getLanguage(rowsBean.getLang());
            myHolder.searchResume_job.setText(DnUtil.getLanguage(rowsBean.getLang()));
        }
        if (rowsBean.getUserType() == null || "".equals(rowsBean.getLang())) {
            myHolder.searchResume_en.setVisibility(View.GONE);
        } else {
            myHolder.searchResume_en.setVisibility(View.VISIBLE);
            if (rowsBean.getUserType().equals("0")) {
                myHolder.searchResume_en.setText(mContext.getString(R.string.chinese));
            } else if (rowsBean.getUserType().equals("1")) {
                myHolder.searchResume_en.setText(mContext.getString(R.string.foreigner));
            } else {
                myHolder.searchResume_en.setText(mContext.getString(R.string.overseas_returnee));
            }
        }
        if ("1".equals(rowsBean.getSex())){
            //男的
            myHolder.mResumeHeadImage.setBackgroundResource(R.mipmap.resume_man);
        }else{
            myHolder.mResumeHeadImage.setBackgroundResource(R.mipmap.resume_nv);
        }

        //条目点击事件
        myHolder.mLinear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ResumeDetailActivity.startAction(mContext,myHolder.mResumeHeadImage);
            }
        });
    }

//        myHolder.searchResume_year.setText(rowsBean.getMember());

    // viewHolder
    public static class MyViewHolder extends RecyclerView.ViewHolder {
        TextView mResumeTime; // 时间
        ImageView mResumeHeadImage; // 头像
        TextView mResumeuantity; // 浏览次数
        TextView mResumeTitle; // 标题
        TextView mResumeSalary; // 月薪
        TextView mResumeAddress; // 地址
        TextView searchResume_year; // 工作时间
        TextView searchResume_education; // 职业
        TextView searchResume_en; // 语言
        TextView searchResume_job; // 行业
        LinearLayout mLinear;

        public MyViewHolder(View itemView) {
            super(itemView);
            mResumeTime = (TextView) itemView.findViewById(R.id.searchResume_time);
            mResumeHeadImage = (ImageView) itemView.findViewById(R.id.searchResume_headImage);
            mResumeuantity = (TextView) itemView.findViewById(R.id.searchResume_quantity);
            mResumeTitle = (TextView) itemView.findViewById(R.id.searchResume_title);
            mResumeSalary = (TextView) itemView.findViewById(R.id.searchResume_salary);
            mResumeAddress = (TextView) itemView.findViewById(R.id.searchResume_address);
            searchResume_year = (TextView) itemView.findViewById(R.id.searchResume_year);
            searchResume_education = (TextView) itemView.findViewById(R.id.searchResume_education);
            searchResume_en = (TextView) itemView.findViewById(R.id.searchResume_en);
            searchResume_job = (TextView) itemView.findViewById(R.id.searchResume_job);
            mLinear = (LinearLayout) itemView.findViewById(R.id.linear);
        }
    }
}
